package com.xcw;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

public class LocalDataTimeUtils {

    public static String LocalDataTime2String(LocalDateTime o){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        Instant instant = o.toInstant(ZoneOffset.ofHours(0));
        LocalDateTime time = LocalDateTime.ofInstant(instant, ZoneId.of("GMT+08:00"));
        return formatter.format(time);
    }

    public static void main(String[] args) {
        String o = "2022-11-08 20:01:14";
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//2.要转换的对象

        LocalDateTime time = LocalDateTime.parse(o,df);

        System.out.println("时间转换前==================" +  time);
        System.out.println("时间转换后==================" + LocalDataTimeUtils.LocalDataTime2String(time));
    }
}
